import { useEffect, useState, useRef, Ref } from 'react';

function useRefState<T>(initialValue: T): [T, (newState: T) => void, { current: T }] {
	const [state, setState] = useState<T>(initialValue);
	const stateRef = useRef<T>(state);

	// useEffect(() => {
	// 	stateRef.current = state;
	// }, [state]);

	const updateState = (newState: T) => {
		setState(newState);
		stateRef.current = newState;
	};

	return [state, updateState, stateRef];
}

export default useRefState;
